<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../css/style.css">
        <script src="../plugins/echarts/echarts.js"></script>
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <style type="text/css">
            .display-flex {
                display: flex;
            }
        </style>
        <!-- 引入组件库 -->
        <script type="text/javascript" src="../js/jquery.min.js"></script>
        <script src="../js/vue.js"></script>
        <script src="../plugins/elementui/index.js"></script>
        <script src="../js/axios-0.18.0.js"></script>
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>统计分析<small>会员数量</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>统计分析</el-breadcrumb-item>
                    <el-breadcrumb-item>会员数量</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">
                    <div id="dateSelector" class="container display-flex">
                        <div class="block">
                            <el-date-picker
                                    v-model="startDate"
                                    type="month"
                                    placeholder="起始日期">
                            </el-date-picker>
                        </div>
                        &nbsp;_&nbsp;
                        <div class="block">
                            <el-date-picker
                                    v-model="endDate"
                                    type="month"
                                    placeholder="结尾日期">
                            </el-date-picker>
                        </div>
                        <el-button @click="handleQuery()">查找</el-button>
                        <el-button @click="handleReset()">重置</el-button>
                    </div>
                    <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
                    <div id="chart1" style="height:600px;"></div>

                    <div class="display-flex">
                        <div id="chart2" style="width:50%; height:600px;"></div>

                        <div id="chart3" style="width:50%; height:600px;"></div>
                    </div>
                </div>
            </div>
        </div>
    </body>
    <script type="text/javascript">
        var myChart1 = echarts.init(document.getElementById('chart1'));
        var myChart2 = echarts.init(document.getElementById('chart2'));
        var myChart3 = echarts.init(document.getElementById('chart3'));
        function setMyOption(chart, json) {
            chart.setOption(json);
        }
        var app = new Vue({
            el:'#dateSelector',
            data:{
                startDate: null,
                endDate: null
            },
            methods:{
                handleQuery() {
                    this.getMemberReportByMonth();
                },
                handleReset() {
                    this.startDate = null;
                    this.endDate = null;
                    this.getMemberReportByMonth();
                },
                formatDate(value) {
                    if (!value) {
                        return null;
                    }
                    return value.getFullYear() + '-' + (value.getMonth() + 1);
                },
                getMemberReportByMonth() {
                    let param = {
                        'startDate':this.formatDate(this.startDate),
                        'endDate':this.formatDate(this.endDate)
                    };
                    axios.post("/report/getMemberReportByMonth.do", param).then((res)=>{
                        if (res.data.flag) {
                            this.$message.success(res.data.message);
                            setMyOption(myChart1, {
                                title: {
                                    text: '会员数量'
                                },
                                tooltip: {},
                                legend: {
                                    data:['会员数量']
                                },
                                xAxis: {
                                    data: res.data.data.months//动态数据
                                },
                                yAxis: {
                                    type:'value'
                                },
                                series: [{
                                    name: '会员数量',
                                    type: 'line',
                                    smooth: true,
                                    data: res.data.data.memberCount
                                }]
                            });
                        } else {
                            this.$message.error(res.data.message);
                        }
                    });
                },
                getMemberReportBySex() {
                    axios.get("/report/getMemberReportBySex.do").then((res)=>{
                        if (res.data.flag) {
                            setMyOption(myChart2, {
                                title: {
                                    text: '会员数量',
                                    subtext: '性别分类',
                                    left: 'center'
                                },
                                tooltip: {
                                    trigger: 'item',
                                    formatter: '{a} <br/>{b} : {c} ({d}%)'
                                },
                                legend: {
                                    orient: 'vertical',
                                    left: 'left',
                                    data: res.data.data.sexNames
                                },
                                series: [
                                    {
                                        name: '性别',
                                        type: 'pie',
                                        radius: '55%',
                                        center: ['50%', '60%'],
                                        data: res.data.data.memberCount,
                                        emphasis: {
                                            itemStyle: {
                                                shadowBlur: 10,
                                                shadowOffsetX: 0,
                                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                                            }
                                        }
                                    }
                                ]
                            });
                        } else {
                            this.$message.error(res.data.message);
                        }
                    });
                },
                getMemberReportByAge() {
                    axios.get("/report/getMemberReportByAge.do").then((res)=>{
                        if (res.data.flag) {
                            myChart3.setOption(
                                {
                                    title: {
                                        text: '会员数量',
                                        subtext: '年龄分类',
                                        left: 'center'
                                    },
                                    tooltip: {
                                        trigger: 'item',
                                        formatter: '{a} <br/>{b} : {c} ({d}%)'
                                    },
                                    legend: {
                                        orient: 'vertical',
                                        left: 'left',
                                        data: res.data.data.ageNames
                                    },
                                    series: [
                                        {
                                            name: '年龄',
                                            type: 'pie',
                                            radius: '55%',
                                            center: ['50%', '60%'],
                                            data: res.data.data.memberCount,
                                            emphasis: {
                                                itemStyle: {
                                                    shadowBlur: 10,
                                                    shadowOffsetX: 0,
                                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                                }
                                            }
                                        }
                                    ]
                                }
                            );
                        } else {
                            this.$message.error(res.data.message);
                        }
                    });
                },
            },
            created() {
                this.getMemberReportByMonth();
                this.getMemberReportBySex();
                this.getMemberReportByAge();
            }
        });
    </script>
</html>
